<?php


use App\Library\Utils\Arr;
use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class SlideSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'CourseSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');
        $courses = $this->fetchAll('SELECT * FROM kg_course');

        $rows = [];
        for ($i = 1; $i < 10; $i++) {
            $course = Arr::rand($courses);
            $targetAttrs = [
                'course' => [
                    'id' => $course['id'],
                    'title' => $course['title'],
                ]
            ];
            $rows[] = [
                'title' => '轮播测试（00'.$i.'）',
                'cover' => $faker->imageUrl(1100, 330),
                'summary' => '',
                'content' => rand(100, 1500),
                'platform' => 1,
                'target' => 1,
                'target_attrs' => $targetAttrs,
                'priority' => $i,
                'published' => 1,
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }

        $this->table('kg_slide')->insert($rows)->saveData();
    }

}
